<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="author" content="featon inc.">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="/static/vendor/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/vendor/photoswipe/dist/default-skin/default-skin.css" />
    <link rel="stylesheet" href="/static/vendor/skin/ftskin.css">
    <title></title>
</head>

<body>

<div class="ft-subpage-wrapper container-fluid">
    <form id="form1" name="form1" action="#" method="post">
        <div class="row">
            <div class="col-lg-12" id="form_table">
                <table id="" class="form-table-border" cellpadding="0" cellspacing="0" style="width:100%">
                    <tr>
                        <td>
                            <ul id="role_list" class="all_user_list" style="margin-bottom:30px;">
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </form>
</div>
<div class="iframe-bottom-tools-box nav navbar-fixed-bottom">
    <button type="button" class="btn btn-info"  id="save_but"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> 保存</button>
    <button type="button" class="btn btn-warning" onclick="modelWindow.closeFrameWindow();"><span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span> 取消</button>
</div>
<input type="hidden" th:id="user_id" th:value="${user_id}" />
<script src="/static/vendor/jquery/jquery-3.3.1.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/vendor/validate/jquery.validate.min.js" type="text/javascript"></script>
<script src="/static/vendor/skin/js/ft-ui.js"></script>
<script src="/static/vendor/skin/js/jquery.c.js"></script>
<script src="/static/vendor/skin/js/java.js"></script>

<script>
    var user_id = $("#user_id").val();

    $(document).ready(function(){
        getRoleList();
        getUserRoleID();
        $('#save_but').click(saveObject)
    });

    function getRoleList()
    {
        var role_list = top.ajax.syncl("/role/getAllRoleList",'')	//RoleRPC.getAllRoleList();

        for(var i=0;i<role_list.length;i++)
        {
            //if(top.LoginUserBean.user_type == 0 || (top.LoginUserBean.user_type == role_list[i].rele_shared))
            $("#role_list").append('<li><input type="checkbox" class="role_id_checkbox" id="role_id_checkbox" value="'+role_list[i].role_id+'"><label>'+role_list[i].role_name+'</label></li>');

        }

    }

    function getUserRoleID()
    {
        //var role_ids = top.ajax.syncl("/sys/cs/org/role/getAllUserRoleIDS/"+user_id,'').result;//RoleRPC.getAllUserRoleIDS(user_id);

        var role_ids = top.ajax.syncl("/userRole/getUserRoleID/"+user_id,'').result;

        if(role_ids != "" && role_ids != null)
        {
            var tempA = role_ids.split(",");
            for(var i=0;i<tempA.length;i++)
            {
                $(":checkbox[value="+tempA[i]+"]").attr("checked",true);
            }
        }
    }
    
    function getSelectedRoleId() {
        var selectedRoleId = "";
        $(".role_id_checkbox").each(function () {
            if ($(this).is(":checked")) {
                selectedRoleId += "," + $(this).val();
            }
        });
        return selectedRoleId.substring(1, selectedRoleId.length);
    }


    function saveObject()
    {
        var role_ids =  getSelectedRoleId();

        var bean = top.ajax.getBean("com.yixun.entity.YxUserRole");
        bean.user_id = user_id;
        bean.role_id = role_ids;

        if(top.ajax.synclBody("/userRole/insertUserRole",bean))
        {
            modelWindow.alert("角色关联"+top.CMSLang.Add_success);
            top.getCurrentFrameObj().loadListble();
            modelWindow.closeFrameWindow();
        }else
            modelWindow.error("角色关联"+top.CMSLang.Add_fail);
    }
</script>
</body>

</html>
